home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 25 / AACD 25.iso / AACD / Magazine / Online / QMail / instutils / MiamiDNSFind.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-01  |  2.1 KB  |  91 lines

  1. /* Parse a Miami settings file and output a resolv.conf file. */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/libraries.h>
  5. #include <exec/execbase.h>
  6. #include <dos/stdio.h>
  7. #include <dos/dosextens.h>
  8. #include <libraries/iffparse.h>
  9.  
  10. #define __NOLIBBASE__
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <proto/iffparse.h>
  14.  
  15. #define ID_MIAM MAKE_ID('M','I','A','M')
  16. #define ID_DBDN MAKE_ID('D','B','D','N')
  17. #define ID_DBDO MAKE_ID('D','B','D','O')
  18.  
  19. LONG tinymain (VOID)
  20. {
  21.     struct ExecBase *SysBase;
  22.     struct DOSBase  *DOSBase;
  23.     struct Library  *IFFParseBase;
  24.  
  25.     SysBase = * (struct ExecBase **) 4;
  26.  
  27.     if ((DOSBase = (struct DOSBase *) OpenLibrary ("dos.library", 33)))
  28.     {
  29.         if ((IFFParseBase = OpenLibrary ("iffparse.library", 33)))
  30.         {
  31.             struct IFFHandle *iffh;
  32.             struct StoredProperty *sp;
  33.  
  34.             if ((iffh = AllocIFF ()))
  35.             {
  36.                 /* Set up standard input as stream. */
  37.                 iffh->iff_Stream = Input ();
  38.                 InitIFFasDOS (iffh);
  39.  
  40.                 if (0 == OpenIFF (iffh, IFFF_READ))
  41.                 {
  42.                     /* Tell the parser to extract these chunks. */
  43.                     PropChunk (iffh, ID_MIAM, ID_DBDN);
  44.                     PropChunk (iffh, ID_MIAM, ID_DBDO);
  45.  
  46.                     /* Tell the parser to stop when it gets to the end of the data. */
  47.                     StopOnExit (iffh, ID_MIAM, ID_FORM);
  48.  
  49.                     /* Parse the settings file. */
  50.                     ParseIFF (iffh, IFFPARSE_SCAN);
  51.  
  52.                     /* Print list of DNS servers, if any. */
  53.                     if ((sp = FindProp (iffh, ID_MIAM, ID_DBDN)))
  54.                     {
  55.                         ULONG i;
  56.                         char *dnsServer = sp->sp_Data;
  57.  
  58.                         for (i = 0; *dnsServer; i ++, dnsServer ++)
  59.                         {
  60.                             PutStr ("nameserver "); PutStr (dnsServer); WriteChar ('\n');
  61.                             while (*dnsServer)
  62.                              dnsServer ++;
  63.                         }
  64.                     }
  65.  
  66.                     /* Print list of domains to search, if any. */
  67.                     if ((sp = FindProp (iffh, ID_MIAM, ID_DBDO)))
  68.                     {
  69.                         ULONG i;
  70.                         char *domain = sp->sp_Data;
  71.  
  72.                         for (i = 0; *domain; i ++, domain ++)
  73.                         {
  74.                             if (i == 0)
  75.                                 PutStr ("domain");
  76.                             WriteChar (' '); PutStr (domain);
  77.                             while (*domain)
  78.                              domain ++;
  79.                         }
  80.                         WriteChar ('\n');
  81.                     }
  82.                     CloseIFF (iffh);
  83.                 }
  84.                 FreeIFF (iffh);
  85.             }
  86.             CloseLibrary (IFFParseBase);
  87.         }
  88.         CloseLibrary ((struct Library *) DOSBase);
  89.     }
  90.     return (RETURN_OK);
  91. }